<template>
  <div>
    <!--    面包屑-->
    <div class="mianbaoxie">
      <el-breadcrumb separator-class="el-icon-arrow-right" style="position:fixed;top: 13%">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>商城管理</el-breadcrumb-item>
        <el-breadcrumb-item>促销管理</el-breadcrumb-item>
        <el-breadcrumb-item>促销活动列表</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="content-box">
      <div>
      <div class="box">

        <el-card class="card1">
          <i class="el-icon-search"></i>
          <span> 筛选查询 </span>
        </el-card>
        <el-card class="class2">
          <el-input v-model="promotionName" placeholder="试用商品名称/关键词" class="input1">
            <el-button
                slot="append"
                icon="el-icon-search"
                @click="loadData"
            ></el-button>
          </el-input>
          <el-date-picker
              v-model="value1"
              type="daterange"
              range-separator="——"
              value-format="yyyy-MM-dd HH:mm:ss"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
          </el-date-picker>
          <el-button @click="loadData">筛选</el-button>
        </el-card>

        <el-card class="card2">
          <i class="el-icon-s-unfold"></i>
          <span> 促销活动列表 </span>

        </el-card>
        <el-table
            :data="promotionList"
            style="width: 100%;">
          <el-table-column
              prop="id"
              label="序号"
          >
          </el-table-column>
          <el-table-column
              prop="promotionCode"
              label="编号"
          >
          </el-table-column>
          <el-table-column
              prop="promotionName"
              label="名称"
          >
          </el-table-column>
          <el-table-column
              label="活动范围"
              prop="prange.rangeName">
          </el-table-column>
          <el-table-column
              prop="ptype.typeName"
              label="活动类别">
          </el-table-column>
          <el-table-column
              prop="promotionIntroduce"
              label="活动介绍">
          </el-table-column>
          <el-table-column
              prop="startTime"
              label="开始时间"
          >
          </el-table-column>
          <el-table-column
              prop="endTime"
              label="结束时间"
          >
          </el-table-column>
          <el-table-column
              label="是否上架">
            <template slot-scope="scope">
              <!--switch 开关 组件-->
              <el-switch
                  @change="alterSwitch(scope.row)"
                  :active-value="true"
                  :inactive-value="false"
                  v-model="scope.row.state"
                  active-color="#13ce66"
                  inactive-color="#ff4949">
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column

              label="操作">
            <template slot-scope="scope">
              <!--    查看数据列表按钮      -->
              <el-button type="primary" plain icon="el-icon-chat-dot-round" circle size="small"
                         @click="view(scope.row)"></el-button>
              <el-button type="danger" plain icon="el-icon-delete" circle size="small"
                         @click="delPromotion(scope.row.id)"></el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

    </div>
    </div>

  </div>
</template>

<script>
export default {
  data(){
    return{
      value1:'',
      promotionList:[],
      promotionName:'',
      startTime:'',
      endTime:'',

    }
  },
  created(){
    this.loadData();
  },
  methods: {
    delPromotion(id){
      this.$confirm('确定删除该促销活动吗？', {
        confirmButtonText: '是的',
        cancelButtonText: '稍等',
        type: 'warning'
      }).then(() => {
        this.$axios({
          method: "get",
          url: "/promotion/delPromotion",
          params: {
            id: id
          }
        }).then(res => {
          if (res.data.code == 200) {
            this.loadData()
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    loadData() {
      if (this.value1.length>1){
        this.startTime = this.value1[0]
        this.endTime = this.value1[1]
      }
      console.log(this.startTime)
      console.log(this.endTime)
      this.$axios({
        method: "get",
        url: "promotion/findAllPromotion",
        params:{
          promotionName:this.promotionName,
          startTime:this.startTime,
          endTime:this.endTime
        }
      }).then(res => {
        if (res.data.code == 200) {
          this.promotionList = res.data.data
          this.startTime=''
          this.endTime = ''
          this.promotionName = ''
          this.value1 = ''
          console.log(this.promotionList)
        }
      })
    },

  }
}
</script>

<style>
.content-box {
  width: 95%;
  height: 70vh;
  background: #FFFFFF;
  box-shadow: 1px 4px 12px #000;
  margin: 0 auto;
  overflow: hidden;
}
.card1 {
  width: 100%;
  font-size: 20px;
  background: #8c939d;
}
.input1 {
  width: 300px;
  margin-right: 10%;
}

.card2 {
  font-size: 20px;
  margin-top: 20px;
  background: #8c939d;
}
</style>